from flask import Flask, request
import uuid

app = Flask(__name__)

TAKS_LIST = {"task_list":[]}
@app.route('/')
def task_list():
    return TAKS_LIST

# 添加任务队列
@app.route('/add_task', methods=['POST'])
def add_task():
    TAKS_LIST["task_list"].append(f"{uuid.uuid4()}")
    return "成功添加任务到队列,请耐心等待!"

# 查询任务队列索引
@app.route('/check_index',methods=['GET','POST'])
def check_index():
    try:
        task_id = request.args.get('task_id')
        index = TAKS_LIST["task_list"].index(task_id)
        return f"当前任务排在:第{index + 1}位置"
    except ValueError:
        return "当前任务不在任务队列,可能已经完成或不存在!"
    
# 结束任务删除任务ID
@app.route('/delete_task',methods=['GET','POST'])
def delete_task():
    try:
        task_id = request.args.get('task_id')
        TAKS_LIST["task_list"].remove(task_id)
        return "任务结束,删除任务队列ID"
    except ValueError:
        return "当前任务不在任务队列,可能已经完成或不存在!"
    
if __name__ == '__main__':
    app.run(debug=True)